#!/bin/bash

###########################
# Help
###########################

usage()
{
cat <<EOF
usage $0 [options] [dir]

Clean .pyc files from subdirectories. If no argument is given, cleans the
current directory and all its subdirectories.

Options:
  --help    Show this information
  --dry-run Show which files will be deleted by the command

Example:
  $0 /opt/groot/bootstrap_ws --dry-run

EOF
}

###########################
# Variable Defaults
###########################

END="-delete"
DIR="."

###########################
# Command Line
###########################

if [ $# -eq 0 ]; then
    usage
    exit 1
fi

for i in "$@"
do
case $i in
    --help)
    usage
    exit 0
    ;;
    --dry-run)
    END="" # if got the dry run arg, don't delete
    ;;
    *)
    DIR=$i
    ;;
esac
done

find $DIR -type f -regex .*.pyc $END
